package com.hnevc.netfoodchoose;

import android.content.Intent;
import android.os.Handler;
import android.os.Message;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.view.menu.MenuView;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;

public class SplashActivity extends AppCompatActivity {


    Handler mHandler = new Handler(){
        public void handleMessage(Message msg){
            if(msg.what==101){

                Intent intent = new Intent();
                intent.setClass(SplashActivity.this,MainActivity.class);

                startActivity(intent);

                SplashActivity.this.finish();
            }
        }
    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_splash);

        ImageView imageView = (ImageView) findViewById(R.id.id_iv_splash);

        Animation animation = AnimationUtils.loadAnimation(this,R.anim.scale_animation);

        imageView.startAnimation(animation);

        new Thread(new Runnable() {
            @Override
            public void run() {
                int i=0;
                while (true){
                    try{
                        Thread.sleep(1000);
                        i++;
                    }catch (InterruptedException e){
                        e.printStackTrace();
                    }

                    if (i==4){
                        Message msg = new Message();
                        msg.what=101;
                        mHandler.sendMessage(msg);
                    }
                }
            }
        }).start();
    }
}
